// pages/code/code.js
Page({


  data: {
    Length: 9, //输入框个数
    isFocus: false, //聚焦
    code: "", //输入的内容
    ispassword: false, //是否密文显示 true为密文， false为明文。
    ShowOrder: false,
    imgUrl: getApp().globalData.imgUrl,
    OrderDetail: [],
    unionShopID: 0,
    ID: 0
  },
  GetOrder: function() {
    var that = this;
    var globalData = getApp().globalData;
    if (that.data.code == "" || that.data.code == null) {
      wx.showToast({
        title: '请输入核销码',
        icon: 'none',

      })
      return;
    }
    var res = wx.getStorageSync('UserInfo');
    var userId = res.UserID;
    var url = globalData.apiurl + '/mobile/api/OrderPickedUp/GetMyOrderList';
    wx.showLoading({
      title: '加载中...',
      mask: true
    });
    wx.request({
      url: url,
      data: {
        "CustID": globalData.custID,
        "PickedUpCode": that.data.code,
        "UnionStoreID": that.data.unionShopID,
        "GoodsStatus": 0,
        "VerificationUser": userId
      },
      method: 'POST',
      header: {
        'content-type': 'application/json',
        'X_ManuName': globalData.manuName
      },
      success: function(res) {
        wx.hideLoading();
        if (res.data.content.Msg == "") {
          var OrderDetail = res.data.content.Order.GetOrderDetails;
          var pickup = res.data.content.Order.OrderPickedUp;
          var id = 0;
          if (pickup != null) {
            id = pickup.ID;
          }
          if (OrderDetail != null && OrderDetail.length > 0) {

            that.setData({
              ID: id,
              OrderDetail: OrderDetail,
              ShowOrder: !that.data.ShowOrder
            });
          } else {
            wx.showToast({
              title: '暂无核销订单',
              icon: 'none',
              duration: 2000
            })
          }

        } else {
          wx.showToast({
            title: res.data.content.Msg,
            icon: 'none',
            duration: 2000
          })
        }



      }
    });

  },
  Focus(e) {
    var that = this;

    var inputValue = e.detail.value;
    that.setData({
      code: inputValue,
    })
  },
  Tap() {
    var that = this;
    that.setData({
      isFocus: true,
    })
  },
  formSubmit(e) {

  },
  DoCheck: function() {
    var that = this;
    var globalData = getApp().globalData;

    var res = wx.getStorageSync('UserInfo');
    var userId = res.UserID;
    var url = globalData.apiurl + '/mobile/api/OrderPickedUp/UpdatePickedUpStatus';
    wx.showLoading({
      title: '处理中...',

      mask: true
    });
    wx.request({
      url: url,
      data: {
        "CustID": globalData.custID,
        "ID": that.data.ID,
        "UnionStoreID": that.data.unionShopID,
        "GoodsStatus": 1,
        "VerificationUser": userId
      },
      method: 'POST',
      header: {
        'content-type': 'application/json',
        'X_ManuName': globalData.manuName
      },
      success: function(res) {
        wx.hideLoading();
        if (res.data.code > 0) {
          wx.showToast({
            title: '核销成功',
            icon: 'success',
            duration: 2000
          })
          that.setData({
            ID: 0,
            OrderDetail: [],
            ShowOrder: false,
            code: ""
          });
        } else {
          wx.showToast({
            title: '核销失败',
            icon: 'none',
            duration: 2000
          })
        }




      }
    });

  },
  close: function() {
    this.setData({
      ShowOrder: false
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },


  onLoad: function(options) {
    var that = this;
    that.setData({
      code: options.code,
      unionShopID: options.unionShopID
    });
  }

})